# 全局最小值不可能在被其它节点更新
from queue import PriorityQueue
def method(m, h, s, t):
    row, col = len(m), len(m[0])
    q = PriorityQueue(row * col)  # distance, (x, y); 注意这里超出大小程序会崩

    # 初始化结点距离的邻接矩阵dis
    dis = []
    for i in range(row):
        dis.append([float('inf')] * col)
    dis[s[0]][s[1]] = 0

    # 每次从队列中取出一个节点，更新关联的节点距离，并将它们加入队列，直到到达T  
    q.put((dis[s[0]][s[1]], (s[0], s[1]) ))
    while not q.empty():
        d, (i, j) = q.get()
        steps = [(i-1, j), (i, j-1), (i, j+1), (i+1, j)]
        for x, y in steps:
            A = 0 <= x and x < row and 0 <= y and y < col and dis[x][y] == float('inf')
            if A:
                z = min(d + m[x][y], dis[x][y])
                dis[x][y] = z 
                q.put((z, (x, y) ))
                if t == (x, y):
                    ans = 'Yes' if h > dis[t[0]][t[1]] else 'No'
                    return ans


def one():
    row, col, h = [int(x) for x in input().split(' ')]
    mx = []
    for _ in range(row):
        s = list(input())
        mx.append(s)
    
    # 定位起点坐标
    for i in range(len(mx)):
        for j in range(len(mx[0])):
            try:
                mx[i][j] = int(mx[i][j])
            except:
                if mx[i][j] == 'S':
                    s = (i, j)
                if mx[i][j] == 'T':
                    t = (i, j)
                mx[i][j] = 0

    ans = method(mx, h, s, t)
    print(ans)


if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        r = one()    
